<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function getImg () {
      return new Promise((resolve, reject) => {
        const oImg = new Image();

        oImg.onload = function () {
          resolve(oImg);
        }

        // https://cdn.eso.org/images/screen/eso1242a.jpg
        oImg.src = 'https://cdn.eso.org/images/publicationjpg/eso1242a.jpg'
      })
    }

    function timeout () {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          reject('图片加载超时')
        }, 1000)
      })
    }

    Promise.race([
      getImg(),
      timeout()
    ])
    .then(res => {
      console.log(res);
    })
    .catch(err => {
      console.log(err);
    })

  </script>
</body>
</html>